
<style>
.tree-header{font-size:14px;font-weight:bold;border-bottom:#ccc solid 1px;padding:5px 0px;}
.cate-item{font-size:14px;margin:0;}
.cate-item dt{padding:5px 0px;}
.tb-model{color:red;}
.show-hide-child{cursor:pointer;}
.show-icon{    color: green;}
</style>
<div class="row-content am-cf">
    <div class="row">

        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">栏目管理</div>
                </div>
                <div class="widget-body am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <a class="am-btn am-btn-default am-btn-success am-radius"
                                       href="<?php echo url('add'); ?>">
                                        <span class="am-icon-plus"></span> 新增
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="am-u-sm-12">
                        <div class="tree-header am-g">
                            <div class="th-name am-u-sm-4">栏目名称</div>
                            <div class="th-model am-u-sm-2">模型</div>
                            <div class="th-sort am-u-sm-1">排序</div>
                            <div class="th-opt am-u-sm-5">操作</div>
                        </div>
                        <?php action('Category/tree', ['tree' => $cateTree , 'level'=>0]); ?>
                    </div>

                </div>

            </div>
        </div>
    </div>
</div>

<script src="/assets/store/js/jquery.cookie.js"></script>
<script>
$(function(){
    Array.prototype.indexOf = function(val) { 
        for (var i = 0; i < this.length; i++) { 
            if (this[i] == val) return i; 
        } 
        return -1; 
    };

    Array.prototype.remove = function(val) { 
        var index = this.indexOf(val); 
        if (index > -1) { 
            this.splice(index, 1); 
        } 
    };

    function addhide(pid){
        var hide = $.cookie('hide') == undefined ? [] :  $.cookie('hide').split(',');
        if(hide.indexOf(pid)< 0){
            hide.push(pid);
        }
        $.cookie('hide', hide.join(',') , { expires: 365, path: '/' });
    }
    function removehide(pid){
        var hide = $.cookie('hide') == undefined ? [] :  $.cookie('hide').split(',');
        hide.remove(pid);
        $.cookie('hide', hide.join(',') , { expires: 365, path: '/' });
    }
    //初始化隐藏栏目
    $('.cat-child').each(function(){
        var hide = $.cookie('hide') == undefined ? [] :  $.cookie('hide').split(',');
        if(hide.indexOf($(this).data('pid'))>-1){
            $(this).css('display' , 'none');
            $(this).parent().find('i').eq(0).removeClass('am-icon-minus-circle').addClass('am-icon-plus-circle');
        }
    });

    var url = "<?php echo url('delete'); ?>";
    $('.item-delete').delete('category_id', url);

    $('.show-hide-child').click(function(){
        var parent = $(this).parent().parent();
        var child = parent.find('dd.cat-child').eq(0);
        if(child.length > 0){
            if(child.css('display') == 'none'){
                child.css('display' , 'block');
                removehide(child.data('pid'));
                parent.find('i.show-icon').eq(0).removeClass('am-icon-plus-circle').addClass('am-icon-minus-circle');
            }else{
                child.css('display' , 'none');
                addhide(child.data('pid'));
                parent.find('i.show-icon').eq(0).removeClass('am-icon-minus-circle').addClass('am-icon-plus-circle');
            }
        }
    });
});
</script>

